<template>
	<div class="mainCon">
		<div class="penalrow selectw100">
			<div class="inlineblock verticalmiddle infoitem">
				<div class="inlineblock verticalmiddle">
					应用名称
				</div>
				<div class="inlineblock verticalmiddle" style="margin-left: 15px;">
					<el-select v-model="appvalue" placeholder="请选择" size="mini">
						<el-option v-for="item in appData" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
				</div>

			</div>
			<div class="basicRightDistanceA" style="position:absolute;">

				<el-button type="primary" size="mini" @click="addRole({isAdd: true})">新增</el-button>
			</div>
		</div>

		<div class="treeparent">
			<div class="inlineblock  tree">
				<el-tree :data="treedata" :props="defaultProps" @node-click="handleNodeClick" node-key="code"  :expand-on-click-node="false" ref = "firstTree"></el-tree>
			</div>
			<div class="inlineblock treeright" style="margin-top: 0;">
				<div class="separaterow" style="margin-top: 0;height:100%;">
					<el-table :data="roleData" style="width: 100%;height: 100%;" :default-sort="{prop: 'order', order: 'ascending'}" size="mini">
						<el-table-column property="name" label="名称" min-width="60px">
						</el-table-column>
            <el-table-column property="laboratoryName" label="所属实验室" min-width="60px">
               <template slot-scope="scope">
                 {{scope.row.laboratoryName == undefined || scope.row.laboratoryName == "" || scope.row.laboratoryName == null? "---" :scope.row.laboratoryName}}
                 </template>
            </el-table-column>
						<el-table-column property="order" label="排序" sortable min-width="60px">
						</el-table-column>
						<el-table-column property="status" label="状态" min-width="60px" :formatter="formatter">
						</el-table-column>

						<el-table-column property="operation" label="操作" min-width="160px">
							<template slot-scope="scope">
								<el-button type="text" size="mini" @click.native="addRole({index:scope.$index, row:scope.row,isAdd: false})">编辑</el-button>
								<el-button type="text" size="mini" @click.native="handleDelete(scope.$index, scope.row)">删除</el-button>
								<el-button type="text" size="mini" @click.native="getassignpriData(scope.$index, scope.row)">分配权限</el-button>
								<el-button type="text" size="mini" @click.native="assignuserData(scope.$index, scope.row)">分配用户</el-button>
							</template>
						</el-table-column>
					</el-table>

				</div>
			</div>
		</div>
		<div class="popupMask" v-if="dialogVisible">
			<div class="popupPenal">
				<div class="popPenalTitle">
					<div class="popPenalTitleName">
						角色管理
					</div>
					<div class="popupClose ensure">
						<el-button type="primary" size="mini" @click="submitForm('roleForm')">保存</el-button>
					</div>
					<div class="popupClose">
						<el-button size="mini" @click="resetForm('roleForm')">关闭</el-button>
					</div>
				</div>
				<div class="penalContent" style="padding: 30px;">
					<el-form label-width="110px" class="demo-ruleForm" :model="roleForm" :rules="rules" ref="roleForm">
						<el-form-item label="名称" prop="name">
							<el-col :span="15">
								<el-input placeholder="名称" v-model="roleForm.name"></el-input>
							</el-col>
						</el-form-item>

            <el-form-item label="实验室">
            	<el-col :span="15">
            		<el-select v-model="roleForm.laboratory" placeholder="请选择" style="width: 100%;" clearable>
            			<el-option v-for="item in labOptions" :key="item.id" :label="item.name" :value="item.id">
            			</el-option>
            		</el-select>
            	</el-col>
            </el-form-item>
            <el-form-item label="排序" prop="order">
            	<el-col :span="15">
            		<el-input placeholder="排序" v-model="roleForm.order"></el-input>
            	</el-col>
            </el-form-item>
						<el-form-item label="状态">
							<el-col :span="15">
								<el-select v-model="roleForm.status" placeholder="请选择" style="width: 100%;">
									<el-option v-for="item in statusoptions" :key="item.value" :label="item.label" :value="item.value">
									</el-option>
								</el-select>
							</el-col>
						</el-form-item>

					</el-form>

				</div>
				<div class="penalFooter" v-if="!isaddrole">

					<p v-if="roleForm.createBy != undefined "><span>创建人 : </span><span>{{roleForm.createBy}}</span></p>
					<p v-if="roleForm.createTime != undefined "><span>创建时间 :</span><span>{{roleForm.createTime}}</span></p>
					<p v-if="roleForm.updateBy != undefined "><span>修改人 : </span><span>{{roleForm.updateBy}}</span></p>
					<p v-if="roleForm.updateTime != undefined"><span>修改时间 : </span><span>{{roleForm.updateTime}}</span></p>
				</div>
			</div>
		</div>
		<div class="popupMask rolePop" v-if="assiginShow">
			<div class="popupPenal">
				<div class="popPenalTitle">
					<div class="popPenalTitleName">
						分配权限  <span style = "font-size:12px;color:#409EFF;margin-left:5px;">{{roleForm.name}}</span>
					</div>
					<div class="popupClose ensure">
						<el-button type="primary" size="mini" @click="importData()" :disabled = "!isRepeat">导入</el-button>
						<el-button type="primary" size="mini" @click="controlSubmit()" :disabled = "!isRepeat">保存</el-button>
					</div>
					<div class="popupClose">
						<el-button size="mini" @click="closeAssiginShow">关闭</el-button>
					</div>
				</div>
				<div class="penalContent" style="padding:0 30px;">
					<div class="inlineblock assigin" style="margin-left: 0;width: 45%;">
						<div class="treeTop">模块权限</div>
						<el-tree :data="modelControl" show-checkbox  node-key="id" :default-checked-keys="menuChecked" ref="tree1" highlight-current :expand-on-click-node="false" :props="modelControlProps">
						</el-tree>
					</div>
					<!---->
					<!-- <div class="inlineblock assigin">
						<div class="treeTop">水司权限</div>
						<el-tree :data="getdeparent" show-checkbox  node-key="code" ref="tree2" highlight-current :default-checked-keys="groupChecked" :expand-on-click-node="false" :props="getdeparentProps">
						</el-tree>
					</div> -->
					<div class="inlineblock assigin" style="width: 45%;">
						<div class="treeTop">实验室权限</div>
						<el-tree :data="expermentControl" v-if = "reload" default-expand-all show-checkbox  node-key="id" ref="tree3" highlight-current :default-checked-keys="labChecked" :expand-on-click-node="false" :props="expermentControlProps">
						</el-tree>
					</div>
				</div>
			</div>
		</div>
		<div class="popupMask people" v-if="aspeopleShow">
			<div class="popupPenal">
				<div class="popPenalTitle">
					<div class="popPenalTitleName">
						分配人员
					</div>
					<div class="popupClose">
						<el-button size="mini" @click="closeAspeople">关闭</el-button>
					</div>
				</div>
				<div class="penalContent" style="padding: 15px;">
					<div class="inlineblock tree" style="margin-left: 0;">
						<el-tree :props="defaultProps1"   :load="loadNode" lazy node-key="code" :expand-on-click-node="false" @node-click="userhandleNode" ref = "treeData"
							:highlight-current="true"
							:default-expanded-keys="['quanbuzuzhi']"
							:default-checked-keys="['quanbuzuzhi']"> </el-tree>
						<!--<el-tree :data="usertreedata" :props="defaultProps" @node-click="userhandleNode" default-expand-all :expand-on-click-node="false"></el-tree>-->
					</div>
					<div class="inlineblock" style="width: 44%;">
						<el-input placeholder="名称" size="mini" v-model="keyName" @keyup.enter.native="cmdfind" style="width: 50%;float: left;height: 40px;"></el-input>

						<el-button size="mini" type="primary" style="float:right" @click="cmdfind">查询</el-button>
						<el-button type="primary" size="mini" style="float:right;margin-right: 10px;" @click="empty">清空</el-button>
						<el-table :data="userData" style="width: 100%;margin-top: 10px;height: calc(100% - 100px);" size="mini" height="tableHeightA">
							<el-table-column property="operation" label="操作" fixed min-width="45px">
								<template slot-scope="scope">
									<el-button type="text" size="mini" @click.native="distributeUser(scope.$index, scope.row)">分配</el-button>

								</template>
							</el-table-column>
							<el-table-column property="name" label="姓名" fixed min-width="80px">
							</el-table-column>
							<el-table-column property="status" label="状态" width="80px">
								<template slot-scope="scope">
									{{scope.row.sex == 1 ? '在职' : '离职'}}
								</template>
							</el-table-column>
							<el-table-column property="loginid" label="账号" min-width="100px">
							</el-table-column>
							<!-- <el-table-column property="sex" label="性别" width="60px">
								<template slot-scope="scope">
									{{scope.row.sex == 1 ? '男' : '女'}}
								</template>
							</el-table-column> -->
							<el-table-column property="departmentname" label="所属单位" min-width="160px">
							</el-table-column>
							<!--<el-table-column property="n" label="工号"    min-width="60px">
							</el-table-column>-->

						</el-table>
						<div class="block  floatright" style="margin-top: 10px;">
							<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="staffQuery.page" :page-sizes="[20,50,100]" :page-size="staffQuery.pageCount" layout="sizes, prev, pager, next" :total="rowNumber" small>
							</el-pagination>
						</div>
					</div>
					<div class="inlineblock" style="width:35%;">
						<p style="height: 30px;">已选员工</p>
						<el-table :data="selectedUser" style="width: 100%;margin-top: 10px;height: calc(100% - 40px);" size="mini">
							<el-table-column prop="sName" label="姓名" width="65px">
							</el-table-column>
							<el-table-column prop="user" label="账号" width="90px">
							</el-table-column>
							<el-table-column prop="dName" label="所属部门">
							</el-table-column>
							<el-table-column label="操作" fixed="right" width="45px">
								<template slot-scope="scope">
									<el-button type="text" size="mini" @click.native="deleletSelected(scope.$index, scope.row)">删除</el-button>
								</template>

							</el-table-column>
						</el-table>
					</div>
				</div>
			</div>
		</div>
		<copy-role :addVisible.sync="copyRoleShow" :appvalue = "appvalue"  :treedata = "treedata" :menuChecked.sync = "menuChecked"></copy-role>
	</div>
</template>
<script>
	import { mapState } from 'vuex';
	import copyRole from './children/copyRole.vue'
	export default {
		data() {
			return {
				controlSendData: [],
				sendModelData: {},
				modelControl: [],
				modelControlProps: {
					children: 'children',
					label: 'name'
				},
				getdeparent: [],
				getdeparentProps: {
					children: 'children',
					label: 'shortname'
				},
				expermentControl: [],
				expermentControlProps: {
					children: 'childs',
					label: 'name'
				},
				dialogVisible: false,
				deleteConfirmShow: false,
				assiginShow: false,
				aspeopleShow: false,
				appData: [],
				appvalue: '',
				treedata: [],
				defaultProps: {
					children: 'sub',
					label: 'ename',
				},
				defaultProps1: {
					children: 'childs',
					label: 'shortname',
					isLeaf: 'leaf'
				},
				roleData: [],
				sendData: {
					target: '',
					appid: '',

				},
				statusoptions: [{
						value: 1,
						label: '停用'
					},
					{
						value: 2,
						label: '启用'
					}
				],
				roleForm: {
					name: '',
					status: 2,
					order: '',
          laboratory:'',
				},
        labOptions:[],
				rules: {
					name: [{
						required: true,
						type: 'string',
						message: '请填写名称',
						trigger: 'blur'
					}, ],
				},
				isaddrole: false,
				selectedtree: false,
				usertreedata: [], //分配人员弹框部门树\
				userData: [],
				keyName: '',
				staffQuery: {
					page: 1, //第几页
					pageCount: 20 //页面得记录条数
				},
				rowNumber: 0,
				selectedUser: [],
				roleId: '',
				isSelected: true,
				labChecked:[],
				menuChecked:[],
				groupChecked:[],
				reload:true,
				isRepeat:true,
				copyRoleShow:false,
        oldLaboratory:"",


			};
		},
		mounted() {
			this.getAppData();
			this.getData();
		},
		components:{
			copyRole
		},
		methods: {
			formatter(row, column) {
				if(row.status == 1) {
					var newStatus = '停用'
				} else if(row.status == 2) {
					var newStatus = '启用'
				}
				return newStatus;
			},
			empty() {
				this.keyName = '';
			},
			getAppData() {
				this.$http({
					method: 'post',
					apiUrl: 'systemmanage/getAppList.htm',
				}).then(res => {
					if(res.code === 0) {
						this.appData = res.data;
						this.appvalue = res.data[0].id;
					}
				})
			},
			getData() {
				this.$http({
					// apiUrl: '/systemmanage/newLabDepartmentTree.htm?level=2',
          apiUrl:"/systemmanage/getGroupList.htm",
					method: "post",
				}).then(res => {
					if(res.code === 0) {
						let setting={
								id:"code",
								pid:"parent",
								root:"",
								data:res.data
							};
              this.treedata = this.$listtotree(setting);
						// this.treedata = [{
						// 		code:"quanbuzuzhi",
						// 		shortname:"所有组织",
						// 		name:"所有组织",
						// 		children:this.$listtotree(setting)
						// 	}
						// ];
						this.$nextTick(() => {
							if(this.treedata.length > 0){
								this.$refs.firstTree.store.nodesMap[this.treedata[0].code].expanded = true;

							}
						})
					}

				})
			},

			handleNodeClick(data) {
				console.log(data)
				if(data.code == undefined) {
					this.sendData.target = data.target;
				} else {
					this.sendData.target = data.code;
				}
				// this.sendData.target = data.code;

				this.sendData.appid = this.appvalue;
				this.$http({
					method: 'get',
					apiUrl: 'systemmanage/selSysRoleListByTarget.htm',
					params: this.sendData,
					isJson: false
				}).then(res => {
					if(res.code == 0) {
						this.roleData = res.data;
					}
				});
				if(data.selectedtree || data.selectedtree == undefined) {
					this.selectedtree = true;
				} else if(!data.selectedtree) {
					this.selectedtree = false;
				}

			},
			//新增，修改
			submitForm(ruleForm) {
				this.$refs[ruleForm].validate((valid) => { //表单验证
					if(valid) {
						if(this.isaddrole) {
							var url = 'systemmanage/addSysRole.htm';
							var data = {
								name: this.roleForm.name,
								appid: this.sendData.appid,
								target: this.sendData.target,
								status: this.roleForm.status,
								order: this.roleForm.order,
                laboratory:this.roleForm.laboratory
							};
              this.submitSysRole(url,data).then((res) => {
                  this.$message({
                  	type: 'success',
                  	message: '提交成功!'
                  });
                  this.resetForm('roleForm');
                  this.handleNodeClick({
                  	target: this.sendData.target,
                  	appid: this.appvalue,
                  	selectedtree: true
                  })
              })
						} else {
							var url = 'systemmanage/updateSysRole.htm';
							var data = {
								id: this.roleForm.id,
								name: this.roleForm.name,
								appid: this.sendData.appid,
								target: this.sendData.target,
								status: this.roleForm.status,
								order: this.roleForm.order,
                laboratory:this.roleForm.laboratory
							};
              // 只要提交的数据中 实验室字段不为空，就要去判断和以前想不想同
              //
              if(this.roleForm.laboratory != "" && this.roleForm.laboratory != null
              && this.roleForm.laboratory != this.oldLaboratory){
                this.$confirm('修改所属实验室将删除该角色下的人员, 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                    this.submitSysRole(url,data).then((res) => {
                        this.$message({
                          type: 'success',
                          message: '提交成功!'
                        });
                        this.resetForm('roleForm');
                        this.handleNodeClick({
                          target: this.sendData.target,
                          appid: this.appvalue,
                          selectedtree: true
                        })
                    })
                }).catch(() => {
                  this.$message({
                    type: 'info',
                    message: '已取消更改'
                  });
                });

              }else{
                this.submitSysRole(url,data).then((res) => {
                    this.$message({
                      type: 'success',
                      message: '提交成功!'
                    });
                    this.resetForm('roleForm');
                    this.handleNodeClick({
                      target: this.sendData.target,
                      appid: this.appvalue,
                      selectedtree: true
                    })
                })
              }


						}
					}
				});
			},
      submitSysRole(url,data){
        return new Promise((resolve, reject) => {
            this.$http({
            	method: 'post',
            	apiUrl: url,
            	params: data,
            	isJson: false,
            }).then(res => {
            	if(res.code == 0) {
                if (res.code == 0) {
                  resolve(res)
                } else {
                  reject(err)
                }
              }
            })
        })
      },

      newGetLaboratory(){
        var data = {
          code:this.sendData.target
        };
        this.$http({
        	apiUrl: 'systemmanage/newGetLaboratoryByGroup.htm',
        	type: 'post',
        	params: data,
        }).then(res => {
        	if(res.code === 0) {
            this.labOptions = res.data;
          }
        })
      },
			addRole(obj) {
				this.isaddrole = obj.isAdd;
        this.newGetLaboratory();
				if(obj.isAdd) {
					if(this.selectedtree) {
						this.roleForm.name = '';
						this.dialogVisible = true;
					} else {
						this.$message({
							type: 'info',
							message: '请选中菜单！'
						})
					}
				} else {
					this.dialogVisible = true;
					for(var i in obj.row) {
						this.roleForm[i] = obj.row[i]
					}
					this.oldLaboratory = JSON.parse(JSON.stringify(this.roleForm.laboratory))
				}

			},
			resetForm(formName) { //重置表单,关闭表单
				this.$refs[formName].resetFields(); //重置表单
				this.roleForm = {
					name: '',
					status: 2,
					order: '',
          laboratory:"",
				}
        this.oldLaboratory = "";
				this.dialogVisible = false; //关闭表单
			},
			handleDelete(key, row) { //表格删除
				this.$confirm('是否删除', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var that = this;
					var param = {
						roleId: row.id,
					}
					this.$http({
						apiUrl: 'systemmanage/delSysRoleById.htm',
						type: 'post',
						params: param,
					}).then(res => {
						if(res.code === 0) {
							this.$message({
								type: 'success',
								message: '删除成功!'
							});
							this.handleNodeClick({
								target: this.sendData.target,
								appid: this.appvalue,
								selectedtree: true
							})
						}
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},

			//打开分配人员渲染树
			assignuserData(key, row) {
				this.roleId = row.id
				this.aspeopleShow = true;
				this.cmdfind(this.staffQuery);
				// this.$http({
				// 	apiUrl: '/systemmanage/departmenttree.htm?flag=2',
				// 	method: "get",
				// }).then(res => {
				// 	if(res.code == 0) {
				// 		this.usertreedata = res.data;
				// 	}

				// })
				this.selectedPeople(this.roleId)
			},
			loadNode(node, resolve) {
				if (node.level === 0) {
					resolve([{ shortname: '所有组织' ,code:"quanbuzuzhi",}])
				}
				if (node.level >= 1){
					this.getusertreedata(node.data).then(res => {
						resolve(res.data);
					})
				}
			},
			getusertreedata(data) {
				return new Promise((resolve, reject) => {
					this.$http({
						apiUrl: 'systemmanage/newDepartmentTree.htm',
						method: "post",
						params: {
							code: data.code
						},
						isJson: false,

					}).then(res => {
						if (res.code == 0) {
							resolve(res)
						}
					})
				})
			},
			//点击分配人员树
			userhandleNode(data) {
				this.orgcode = data.code;
				this.cmdfind(this.staffQuery);
			},
			//渲染员工列表
			cmdfind(parp) {
				var sendData = {
					name: this.keyName,
					orgcode: this.orgcode,
					page: parp.page, //第几页
					pageCount: parp.pageCount //页面得记录条数
				};
				this.$http({
					method: 'post',
					apiUrl: 'systemmanage/staffquery.htm',
					params: sendData,
					isJson: false,
				}).then(res => {
					if(res.code == 0) {
						this.userData = res.data;
						if(!res.pageinfo) {
							this.rowNumber = 0;
						} else if(res.pageinfo && !res.pageinfo.rowNumber) {
							this.rowNumber = 0;
						} else {
							this.rowNumber = res.pageinfo.rowNumber;
						}
					}

				})

			},
			//分配人员
			distributeUser(key, row) {
				this.$confirm('确定分配该人员？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					//比较该员工是否已经被分配
					for(var i = 0; i < this.selectedUser.length; i++) {
						if(row.loginid == this.selectedUser[i].user) {
							this.$message({
								type: 'info',
								message: '改员工已经分配!'
							});
							this.isSelected = false
							break;
						} else {
							this.isSelected = true
						}
					}
					if(this.isSelected) {
						var that = this;
						var user = {
							role: this.roleId,
							user: row.loginid
						}
						this.$http({
							apiUrl: 'systemmanage/addSysRoleUser.htm',
							type: 'post',
							params: user,
						}).then(res => {
							if(res.code === 0) {
								this.$message({
									type: 'success',
									message: '分配成功!'
								});
								this.selectedPeople(this.roleId)
							}

						});
					}
				}).catch(() => {

				});
			},
			//已选员工
			selectedPeople(roleid) {
				var roleid = {
					roleId: this.roleId
				};
				this.$http({
					apiUrl: 'systemmanage/selSysRoleUserById.htm',
					method: "get",
					params: roleid,
				}).then(res => {
					if(res.code === 0) {
						this.selectedUser = res.data;
					}

				})
			},
			//删除已选员工
			deleletSelected(key, row) {
				this.$confirm('是否删除', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var that = this;
					var param = {
						roleId: row.role,
						loginName: row.user
					}
					this.$http({
						apiUrl: 'systemmanage/delSysRoleUserByUser.htm',
						type: 'post',
						params: param,
					}).then(res => {
						if(res.code === 0) {
							this.$message({
								type: 'success',
								message: '删除成功!'
							});
							this.selectedPeople(this.roleId)

						}
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			closeAspeople() {
				this.aspeopleShow = false;
				this.keyName = ''
				this.orgcode = "";

			},
			//获取角色的权限分配信息
			getassignpriData(key, row) {
				this.assiginShow = true;

				this.getModelControl(this.appvalue);
				// this.getdeparentControl();
				this.getLaboratory();
				for(var i in row) {
					this.roleForm[i] = row[i]
				}
				var sendData = {
					roleId: this.roleForm.id
				}
				this.$http({
					apiUrl: 'systemmanage/selSysRoleFunctionByRoleId.htm',
					method: "get",
					params: sendData,

				}).then(res => {
					if(res.code == 0) {
						this.$refs.tree1.setCheckedKeys([]);
						// this.$refs.tree2.setCheckedKeys([]);
						this.$refs.tree3.setCheckedKeys([]);
						this.labChecked = [];
						this.groupChecked = [];
						this.menuChecked = [];
						for(var i = 0; i < res.data.length; i++) {
							if(res.data[i].target == 'oper'){
								this.menuChecked.push(res.data[i].oid)
							}
							if(res.data[i].target == 'group') {
								this.groupChecked.push(res.data[i].oid)
							}
							if(res.data[i].target == 'lab') {
								this.labChecked.push(res.data[i].oid)
							}
						}

					}

				})

			},
			//关闭分配权限弹框
			closeAssiginShow(){
				this.isRepeat = true;
				this.assiginShow=false
			},
			// 是否重新加载
			reLoad() {
				this.reload = false;
				this.$nextTick(() => {
					this.reload = true;
				})
			},
			//分配权限中模块权限
			getModelControl() {
				var params = {
					appId: this.appvalue
				};
				this.$http({
					apiUrl: 'systemmanage/modeltree.htm',
					method: "get",
					params: params,
				}).then(res => {
					if(res.code == 0) {
						this.modelData = res.data
						let setting = {
							id: "id",
							pid: "parent",
							root: "",
							data: res.data
						};
						this.modelControl = this.$listtotree(setting);
						this.$nextTick(() => {
							if(this.modelControl.length > 0){
								this.$refs.tree1.store.nodesMap[this.modelControl[0].id].expanded = true;
							}

						})
					}

				})
			},
			//水司权限
			getdeparentControl() {
				this.$http({
					apiUrl: '/systemmanage/newLabDepartmentTree.htm?level=2',
					method: "post",
				}).then(res => {
					if(res.code === 0) {
						let setting={
								id:"code",
								pid:"supercode",
								root:"quanbuzuzhi",
								data:res.data
							};

						this.getdeparent = [{
								code:"quanbuzuzhi",
								shortname:"所有组织",
								children:this.$listtotree(setting)
							}
						];
						console.log(this.getdeparent)
						this.$nextTick(() => {
							if(this.getdeparent.length > 0){
								this.$refs.tree2.store.nodesMap[this.getdeparent[0].code].expanded = true;
								// for(var i in this.getdeparent[0].children){
								// 	var code = this.getdeparent[0].children[i].code
								// 	this.$refs.tree2.store.nodesMap[code].expanded = true;
								// }
							}
						})
					}

				})
			},
			//实验室权限
			getLaboratory() {
				this.$http({
					apiUrl: 'systemmanage/getLaboratoryTree.htm',
					method: "get",
				}).then(res => {
					if(res.code === 0) {
						this.expermentControl = res.data;

					}
				})
			},
			controlSubmit() {
				this.controlSendData = [];
				this.isRepeat = false;
				//模块权限
				let model = this.$refs.tree1.getCheckedNodes()
				let sendModelData = {};
				for(let i in model) {
					sendModelData = {}
					sendModelData.role = this.roleForm.id;
					sendModelData.target = model[i].type;
					sendModelData.oid = model[i].id;
					this.controlSendData.push(sendModelData)
				}
				//水司权限
				// let shuisi = this.$refs.tree2.getCheckedNodes();
				// let senddepData = {}
				// for(let i in shuisi) {
				// 	senddepData = {}
				// 	senddepData.role = this.roleForm.id;
				// 	senddepData.target = 'group';
				// 	senddepData.oid = shuisi[i].code;
				// 	this.controlSendData.push(senddepData)
				// }
				//实验室权限
				let lab = this.$refs.tree3.getCheckedNodes();
				let sendlabData = {}
				for(let i in lab) {
					sendlabData = {}
					if(lab[i].id != "root") {
						sendlabData.role = this.roleForm.id;
						sendlabData.target = 'lab';
						sendlabData.oid = lab[i].id;
						this.controlSendData.push(sendlabData)
					}
				}
				for(var i in this.controlSendData){
					if(this.controlSendData[i].target == "lab"){
						console.log(this.controlSendData[i])
					}
				}

				if(this.controlSendData.length == 0) {
					var sendSumData = {
						role: this.roleForm.id
					}
					this.controlSendData.push(sendSumData)
				}
				this.$http({
					method: 'post',
					apiUrl: 'systemmanage/addSysRoleFunction.htm',
					params: this.controlSendData, //param,
					isJson: true,
				}).then(res => {
					this.isRepeat = true;
					if(res.code == 0) {
						this.$message({
							type: 'success',
							message: '分配成功!'
						});
						this.assiginShow = false;
					}

				}).catch(() => {

				});

			},
			// 权限导入
			importData(){
				this.copyRoleShow = true;
			},
			handleCurrentChange: function(val) {
				this.staffQuery.page = val;
			},
			handleSizeChange: function(val) {
				this.staffQuery.pageCount = val;
			},
			assignpri() {
				this.assiginShow = true;
			},
			assignuser() {
				this.aspeopleShow = true;
			},

		},
		watch: {
			appvalue: {
				handler(val, oldVal) {
					this.handleNodeClick({
						target: this.sendData.code,
						appid: this.appvalue,
						selectedtree: false
					})
				},
				deep: true
			},
			staffQuery: {
				handler(val, oldVal) {
					this.cmdfind(this.staffQuery)
				},
				deep: true
			},

		},
		computed: {
			...mapState(['tableHeightA'])

		},

	}
</script>

<style scoped>
	.treeTop {
		text-align: left;
		margin: 10px 0;
	}

	.assigin {
		width: calc(100%/3);
		height: 100%;
		float: left;
		padding-left: 10px;
		margin-left: 15px;
	}

	.assigin .el-tree {
		height: calc(100% - 50px);
		overflow: auto;
	}

	.penalContent {
		bottom: 0;
	}
	.popupMask.rolePop .popupPenal{
		height: 100%;
		width: 100%;
	}

	.popupMask.people .inlineblock.tree {
		width: 16%;
	}

	.popupMask.people .popupPenal {
		min-width: 85%;
		min-height: 80%;
	}

	.popupMask.people .inlineblock {
		height: 100%;
		overflow: auto;
		float: left;
		margin-left: 10px;
	}

	.popupMask.people .block.floatright {
		width: 100%;
		height: 50px;
		overflow: auto;
		text-align: right;
	}

	.el-table {
		height: calc(100% - 27px);
	}

	.el-table__body-wrapper::-webkit-scrollbar,
	.block.floatright::-webkit-scrollbar,
	.assigin .el-tree::-webkit-scrollbar {
		width: 0.4rem;
		height: 0.4rem;
	}

	.el-table__body-wrapper::-webkit-scrollbar-thumb,
	.block.floatright::-webkit-scrollbar-thumb,
	.assigin .el-tree::-webkit-scrollbar-thumb {
		border-radius: 0.3rem;
		-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
		background: #e5e5e5;
	}

	.el-table .cell {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap !important;
	}
	.treeparent {
		height: calc(100% - 50px);
		overflow: auto;
	}
	.tree {
		width: 23%;
		height: calc(100% - 10px);
		overflow: auto;
		background: #fff;
	}
	.treeright {
		margin-left: 10px;
		width: calc(76% - 10px);
		height: 100%;
		vertical-align: top;
	}
	.infoitem {
		width: calc(100%/2);
		padding-right: 20px;
	}
</style>
